package com.applink.sell_proof.database.table;

import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

import com.applink.sell_proof.EMarketing;
import com.applink.sell_proof.constant.Constant;
import com.applink.sell_proof.model.CustomerSupport;
import com.applink.sell_proof.model.UserProfile;

public class CustomerSupportHelper {

	public static boolean InsertCustomerSupport(CustomerSupport paramEntity) {
		Editor editor = EMarketing.getInstance().getApplicationContext()
				.getSharedPreferences(Constant.SHAREDPREFERENCE_NAME, 0).edit();
		editor.putString(Constant.CLIENT_SALE_EMAIL,
				paramEntity.getClient_sale_email());
		editor.putString(Constant.CLIENT_SALE_HOTLINE,
				paramEntity.getClient_sale_hotline());
		editor.putString(Constant.CLIENT_TECH_EMAIL,
				paramEntity.getClient_tech_email());
		editor.putString(Constant.CLIENT_TECH_HOTLINE,
				paramEntity.getClient_tech_hotline());
		editor.putString(Constant.PROGRAM_EMAIL, paramEntity.getProgramemail());
		editor.putString(Constant.PROGRAM_HOTLINE,
				paramEntity.getProgramhotline());

		return editor.commit();

	}

	public static boolean InsertUserPorfileToSharePref(UserProfile userProfile) {
		Editor editor = EMarketing.getInstance().getApplicationContext()
				.getSharedPreferences(Constant.SHAREDPREFERENCE_USERPROFILE, 0)
				.edit();

		editor.putInt(Constant.USPF_COUNTRYCODE, userProfile.getCountryCode());
		editor.putString(Constant.USPF_COUNTRY, userProfile.getCountryName());
		editor.putString(Constant.DELIVERY_BUILDNAME,
				userProfile.getDeliAddBuildName());
		editor.putInt(Constant.DELIVERY_COUNTRYCODE,
				userProfile.getDeliAddCountryCode());
		editor.putString(Constant.DELIVERY_COUNTRY,
				userProfile.getDeliAddCountryName());
		editor.putString(Constant.DELIVERY_POSTALCODE,
				userProfile.getDeliAddPostalCode());
		editor.putString(Constant.DELIVERY_STREETNAME,
				userProfile.getDeliAddStreetName());
		editor.putString(Constant.DELIVERY_UNIT, userProfile.getDeliAddUnit());

		editor.putString(Constant.USPF_DESIGNATION,
				userProfile.getDesignation());
		editor.putString(Constant.USPF_EMAIL, userProfile.getEmail());
		editor.putString(Constant.USPF_FIRSTNAME, userProfile.getFirstname());
		editor.putString(Constant.USPF_LASTNAME, userProfile.getLastname());
		editor.putString(Constant.USPF_MOBILE, userProfile.getMobileNo());
		editor.putString(Constant.OFFICE_BUILDNAME,
				userProfile.getOffAddBuildName());

		editor.putInt(Constant.OFFICE_COUNTRYCODE,
				userProfile.getOffAddCountryCode());
		editor.putString(Constant.OFFICE_COUNTRY,
				userProfile.getOffAddCountryName());
		editor.putString(Constant.OFFICE_POSTALCODE,
				userProfile.getOffAddPostalCode());
		editor.putString(Constant.OFFICE_STREETNAME,
				userProfile.getOffAddStreetName());
		editor.putString(Constant.OFFICE_UNIT, userProfile.getOffAddUnit());
		editor.putString(Constant.USPF_ORGANNAME, userProfile.getOrangeName());
		editor.putString(Constant.USPF_SALUTATION, userProfile.getSalutation());
		// editor.putString(Constant.USPFDELI_ISSAME,Boolean.toString(paramEntity.getSameAsOffAdd()));
		editor.putString(Constant.USPF_USERID, userProfile.getUserID());

		return editor.commit();

	}

	public static boolean InsertUserPorfileToSharePref(String AddStreetName,
			String AddBuildName, String AddUnit, String DeliAddBuildName,
			String DeliAddStreetName, String DeliAddUnit, String CountryOffPos,
			String CountryDeliPos) {
		Editor editor = EMarketing.getInstance().getApplicationContext()
				.getSharedPreferences(Constant.SHAREDPREFERENCE_USERPROFILE, 0)
				.edit();

		editor.putString(Constant.OFFICE_COUNTRYCODE, CountryOffPos);
		editor.putString(Constant.DELIVERY_COUNTRYCODE, CountryDeliPos);
		editor.putString(Constant.DELIVERY_BUILDNAME, DeliAddBuildName);
		editor.putString(Constant.DELIVERY_STREETNAME, DeliAddStreetName);
		editor.putString(Constant.DELIVERY_UNIT, DeliAddUnit);

		editor.putString(Constant.OFFICE_BUILDNAME, AddBuildName);
		editor.putString(Constant.OFFICE_STREETNAME, AddStreetName);
		editor.putString(Constant.OFFICE_UNIT, AddUnit);

		return editor.commit();

	}

	public static boolean InsertUserPorfileToSharePref(String paramdesignation,
			String paramMobile, String paramEmail) {
		Editor editor = EMarketing.getInstance().getApplicationContext()
				.getSharedPreferences(Constant.SHAREDPREFERENCE_USERPROFILE, 0)
				.edit();

		editor.putString(Constant.USPF_DESIGNATION, paramdesignation);
		editor.putString(Constant.USPF_EMAIL, paramEmail);
		editor.putString(Constant.USPF_MOBILE, paramMobile);

		return editor.commit();

	}

	public static UserProfile GetUserProfile() {

		SharedPreferences settings = EMarketing.getInstance()
				.getSharedPreferences(Constant.SHAREDPREFERENCE_USERPROFILE, 0);
		String returnVal = settings.getString(Constant.USPF_FIRSTNAME, "");

		if (returnVal == "")
			return null;

		UserProfile entity = new UserProfile();

		entity.setCountryName(settings.getString(Constant.USPF_COUNTRY, ""));
		entity.setCountryCode(settings.getInt(Constant.USPF_COUNTRYCODE, 0));
		entity.setDeliAddBuildName(settings.getString(
				Constant.DELIVERY_BUILDNAME, ""));
		entity.setDeliAddCountryCode(settings.getInt(
				Constant.DELIVERY_COUNTRYCODE, 0));
		entity.setDeliAddCountryName(settings.getString(
				Constant.DELIVERY_COUNTRY, ""));
		entity.setDeliAddPostalCode(settings.getString(
				Constant.DELIVERY_POSTALCODE, ""));
		entity.setDeliAddStreetName(settings.getString(
				Constant.DELIVERY_STREETNAME, ""));
		entity.setDeliAddUnit(settings.getString(Constant.DELIVERY_UNIT, ""));

		entity.setDesignation(settings.getString(Constant.USPF_DESIGNATION, ""));
		entity.setEmail(settings.getString(Constant.USPF_EMAIL, ""));
		entity.setFirstname(settings.getString(Constant.USPF_FIRSTNAME, ""));
		entity.setLastname(settings.getString(Constant.USPF_LASTNAME, ""));
		entity.setMobileNo(settings.getString(Constant.USPF_MOBILE, ""));
		entity.setOffAddBuildName(settings.getString(Constant.OFFICE_BUILDNAME,
				""));

		entity.setOffAddCountryCode(settings.getInt(
				Constant.OFFICE_COUNTRYCODE, 0));
		entity.setOffAddCountryName(settings.getString(Constant.OFFICE_COUNTRY,
				""));
		entity.setOffAddPostalCode(settings.getString(
				Constant.OFFICE_POSTALCODE, ""));
		entity.setOffAddStreetName(settings.getString(
				Constant.OFFICE_STREETNAME, ""));
		entity.setOffAddUnit(settings.getString(Constant.OFFICE_UNIT, ""));
		entity.setOrangeName(settings.getString(Constant.USPF_ORGANNAME, ""));
		entity.setSalutation(settings.getString(Constant.USPF_SALUTATION, ""));
		entity.setUserID(settings.getString(Constant.USPF_USERID, ""));
		entity.setUserPassw(settings.getString(Constant.USPF_USERPASSW, ""));

		return entity;
	}

	public static CustomerSupport GetCustomerInfo() {

		SharedPreferences settings = EMarketing.getInstance()
				.getSharedPreferences(Constant.SHAREDPREFERENCE_NAME, 0);
		String returnVal = settings.getString(Constant.PROGRAM_HOTLINE, "");

		if (returnVal == "")
			return null;

		CustomerSupport entity = new CustomerSupport();

		entity.setProgramhotline(settings.getString(Constant.PROGRAM_HOTLINE,
				""));
		entity.setProgramemail(settings.getString(Constant.PROGRAM_EMAIL, ""));
		entity.setClient_sale_email(settings.getString(
				Constant.CLIENT_SALE_EMAIL, ""));
		entity.setClient_sale_hotline(settings.getString(
				Constant.CLIENT_SALE_HOTLINE, ""));
		entity.setClient_tech_email(settings.getString(
				Constant.CLIENT_TECH_EMAIL, ""));
		entity.setClient_tech_hotline(settings.getString(
				Constant.CLIENT_TECH_HOTLINE, ""));

		return entity;
	}

	public static boolean storeString(String key, String value) {
		Editor editor = EMarketing.getInstance().getApplicationContext()
				.getSharedPreferences(Constant.SHAREDPREFERENCE_USERPROFILE, 0)
				.edit();
		editor.putString(key, value);
		return editor.commit();
	}

	public static String getString(String key) {
		SharedPreferences settings = EMarketing.getInstance()
				.getSharedPreferences(Constant.SHAREDPREFERENCE_USERPROFILE, 0);
		return settings.getString(key, null);
	}

	public static boolean storeBoolean(String key, boolean value) {
		Editor editor = EMarketing.getInstance().getApplicationContext()
				.getSharedPreferences(Constant.SHAREDPREFERENCE_USERPROFILE, 0)
				.edit();
		editor.putBoolean(key, value);
		return editor.commit();
	}

	public static boolean getBoolean(String key) {
		SharedPreferences settings = EMarketing.getInstance()
				.getSharedPreferences(Constant.SHAREDPREFERENCE_USERPROFILE, 0);
		return settings.getBoolean(key, false);
	}

	public static boolean storeInt(String key, int value) {
		Editor editor = EMarketing.getInstance().getApplicationContext()
				.getSharedPreferences(Constant.SHAREDPREFERENCE_USERPROFILE, 0)
				.edit();
		editor.putInt(key, value);
		return editor.commit();
	}

	public static int getInt(String key) {
		SharedPreferences settings = EMarketing.getInstance()
				.getSharedPreferences(Constant.SHAREDPREFERENCE_USERPROFILE, 0);
		return settings.getInt(key, 0);
	}

}
